/*
  File:    Matrix.h
  Purpose: To provide an easy-to-use matrix object for 
           passing data, as well as reading/writing 
		   from/to files. Many common Matlab-like 
		   functions are provided.

  Contact: Paul Macklin
           pmacklin@math.uci.edu
		   http://math.uci.edu/~pmacklin
*/

#ifndef __Matrix__
#define __Matrix__

class Matrix{
private:
 int Rows;
 int Cols;
 double** Data;
 
public:
 // initializers
 
 Matrix();
 Matrix( int NewRows , int NewCols );
 Matrix( const Matrix& Input );
 
 // destructor 
 
 ~Matrix();
 
 // some read & write functions
 
 bool ReadFromFile( char* FileName ); // 
 bool WriteToFile( char* FileName ); //

 bool ReadFromTextFile( char* FileName ); //
 bool WriteToTextFile( char* FileName ); //
 
 bool ReadFromBigEndianMachine( char* FileName );
 bool WriteToBigEndianMachine( char* FileName );
 
 // overloaded operators
 
 Matrix operator+( const Matrix& B );
 double* operator()( int i, int j ) const;
 double* operator()( int j ) const;
 Matrix& operator=( const Matrix& B );
 Matrix operator-( const Matrix& Input );
// friend Matrix operator*( double d , Matrix& Input );
 Matrix operator*( Matrix &Input2);
 friend Matrix operator*( double d, Matrix Input2);
 
 // other functions

 int TellRows( void ) const;
 int TellCols( void ) const;
 void SetSize( int NewRows, int NewCols );

 void display( void );

 double InfinityNorm( void );
 double Pnorm( double p );
 double IntPnorm( int p );

 Matrix submatrix( int StartRow, int EndRow, 
                   int StartCol, int EndCol );
				   
 void UpdateSubmatrix( Matrix& Input, int StartRow, int EndRow, 
                                      int StartCol, int EndCol );
};

#endif

Matrix zeros( int NewRows, int NewCols );
Matrix ones( int NewRows, int NewCols );

double DotProduct(Matrix &In1 , int Row1, int StartCol1 ,
                  Matrix &In2 , int Row2, int StartCol2 , 
                  int NumberOfSummands);

Matrix GaussianEliminationPartialPivoting( 
        Matrix &Coefficient, Matrix &RHS );
		
Matrix Transpose( Matrix& Input );		
Matrix linspace( double left, double increment, double right );
Matrix linspace( double left, double right, int size );

double DotProduct( Matrix& Input1 , Matrix& Input2 );
Matrix CrossProduct( Matrix& Input1, Matrix& Input2 );

Matrix linsolve2by2( Matrix& A, Matrix& b );
